package com.quyetnd.cocos.android.core;

import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;

import com.quyetnd.cocos.android.scene.GameScene;

import android.os.Bundle;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;

public class CocosAndroidActivity extends Activity {
	protected CCGLSurfaceView _glSurfaceView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);    
        _glSurfaceView = new CCGLSurfaceView(this);   
        setContentView(_glSurfaceView);
    }

    @Override
    public void onStart(){
        super.onStart();   
        CCDirector.sharedDirector().attachInView(_glSurfaceView);     
        CCDirector.sharedDirector().setDisplayFPS(true);     
        CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
        
        CCDirector.sharedDirector().runWithScene(GameScene.scene());
    }
    
    @Override
    public void onPause(){
        super.onPause();   
        CCDirector.sharedDirector().pause();
    }
     
    @Override
    public void onResume(){
        super.onResume();    
        CCDirector.sharedDirector().resume();
    }
     
    @Override
    public void onStop(){
        super.onStop();    
        CCDirector.sharedDirector().end();
    }
}
